import schedule
import time
import json
from src.notifier import fetch_notifications
from src.sms_sender import send_sms


def job():
    with open('config.json', 'r') as file:
        config = json.load(file)

    notifications = fetch_notifications(config["website_url"])
    for notification in notifications:
        message = {
            "message": f"New notification: {notification['title']}. Check it out at {notification['link']}"
        }
        send_sms(config["sms"]["receiver"], config["sms"]["sign_name"], config["sms"]["template_code"], message)
        break  # 仅为示例，实际可能需要根据实际情况调整


schedule.every(30).minutes.do(job)

if __name__ == "__main__":
    while True:
        schedule.run_pending()
        time.sleep(1)
